//
//  Downloader.h
//  lib
//
//

#import <Foundation/Foundation.h>

enum
{
	DL_RESPONSE_NG		= 0,
	DL_RESPONSE_OK,
	DL_RESPONSE_WAIT,
};
typedef int DLResponse;

enum
{
	DL_PRIORITY_TOP = 0,
	DL_PRIORITY_FIRST,
	DL_PRIORITY_NORMAL,
	DL_PRIORITY_BOTTOM,
};


@protocol DownloadProtocol

- (void)downloaderError:(NSString*)url_path;
- (void)downloaderCancel;
- (void)downloaderFinish:(NSData*)data saveName:(NSString*)save_name;
@optional
- (BOOL)downloaderUseActivityIndicator;
- (void)downloaderStart:(NSString*)save_name;
- (BOOL)downloaderConnection:(NSData*)data;
- (void)downloaderFinishAfter;
@end


@interface libDownloadInfo : NSObject
{
	NSString*		url_path;		// URL
	NSString*		save_name;		// save name
	id				delegate;
	int				priority;
}
@property(nonatomic, readonly) NSString*	url_path;
@property(nonatomic, readonly) NSString*	save_name;
@property(nonatomic, readonly) id			delegate;
@property(nonatomic, readonly) int			priority;

- (id)initWithSet:(NSString*)url_path_arg saveName:(NSString*)save_name_arg delegate:(id)delegate_arg priority:(int)priority_arg;
- (void)set:(NSString*)url_path_arg saveName:(NSString*)save_name_arg delegate:(id)delegate_arg priority:(int)priority_arg;
- (void)reset;

@end


@interface Downloader : NSObject
{
	NSURLConnection*	m_UrlConect;	
	NSString*			m_UrlPath;
	NSString*			m_SaveName;		
	NSMutableData*		m_Data;			
	BOOL				m_IsDownload;	
	NSMutableArray*		m_DownloadArray;
	
	id					m_pDelegate;	

	int					m_StatusCode;	
}
@property(nonatomic, readonly) int	m_StatusCode;

- (BOOL)start:(NSString*)url_path saveName:(NSString*)save_name delegate:(id)delegate;
- (BOOL)startWithRequest:(NSMutableURLRequest*)req saveName:(NSString*)save_name delegate:(id)delegate;
- (void)cancelForDelegate:(id)delegate;
- (void)cancel:(id)delegate;
- (void)cancel;
- (void)cancelAll;
- (BOOL)isExec;
- (DLResponse)requestDownload:(id)request_obj urlPath:(NSString*)url_path saveName:(NSString*)save_name delegate:(id)delegate;
- (DLResponse)requestDownload:(NSString*)url_path saveName:(NSString*)save_name delegate:(id)delegate priority:(int)priority;
- (void)update;

@end